<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>华胜后台管理</title>
    <link rel="stylesheet" type="text/css" href="css/unified.css">
    <script src="plugins/layui/layui.js"></script>

    <style type="text/css">
        .searchform span{margin-left: 10px}
        .layui-table-view .layui-table td, .layui-table-view .layui-table th{padding: 0}
        .layui-col-md6{padding: 0 10px;}
    </style>
</head>
<body>

    <div class="breadcrumbnav">
        <span class="layui-breadcrumb " lay-separator="·">
          <a ><cite>首页</cite></a>
          <a ><cite>委托加工单据处理</cite></a>
          <a ><cite>委托加工材料入库</cite></a>
        </span>
    </div>
    <div class="kit-doc">
        <!-- 标题 -->
        <div class="kit-doc-title">
            <fieldset>
                <legend> <a name="blockquote">入库</a>
                </legend>
            </fieldset>
        </div>
        <!-- 标题 end-->
        
        
        <!-- 概述 -->
        <div class="boderbox">
       		<div class="rowtop">
	            <button class="layui-btn addbtn openwinbtn" data-method="addmang">添加+</button>
            </div>
            <div class="layui-tab-content notab">
                <div class="layui-tab-item layui-show">
                    <table class="layui-table " lay-filter="table100" id="EOtable"></table>
                </div>
             </div>
		</div>
		
		<script id="addBox" type="text/html">
			<div class=" layui-layer-wrap">
                <form class="layui-form layui-form-pane" action="" id="addform" >
                    
                    <div class="layui-col-xs12 layui-col-sm6 layui-col-md6">
                    	 <div class="layui-form-item">
						    <label class="layui-form-label">委托单号</label>
						    <div class="layui-input-block">
						      <input type="number" name="entrustNumber" autocomplete="off"    placeholder="" class="layui-input">
						    </div>
						  </div>
                    </div>
                   	<div class="layui-col-xs12 layui-col-sm6 layui-col-md6">
                    <div class="layui-form-item">
					    <label class="layui-form-label">批次id</label>
					    <div class="layui-input-block">
					      <input type="number" name="batchId" autocomplete="off"    placeholder="" class="layui-input">
					    </div>
					</div>
					</div>
                   	<div class="layui-col-xs12 layui-col-sm6 layui-col-md6">
                    <div class="layui-form-item">
					    <label class="layui-form-label">提货点编码</label>
					    <div class="layui-input-block">
					      <input type="number" name="locationId" autocomplete="off"    placeholder="" class="layui-input">
					    </div>
					</div>
					</div>
                   	<div class="layui-col-xs12 layui-col-sm6 layui-col-md6">
					<div class="layui-form-item">
					    <label class="layui-form-label">入库数量</label>
					    <div class="layui-input-block">
					      <input type="number" name="theNum" autocomplete="off"    placeholder="" class="layui-input">
					      
					    </div>
					</div>
					</div>
                   	<div class="layui-col-xs12 layui-col-sm6 layui-col-md6">
					<div class="layui-form-item">
					    <label class="layui-form-label">供应商名称</label>
					    <div class="layui-input-block">
					      <input type="text" name="supplierName" autocomplete="off"  placeholder=""   class="layui-input">
					    </div>
					</div>
					</div>
                   	<div class="layui-col-xs12 layui-col-sm6 layui-col-md6">
					<div class="layui-form-item">
					    <label class="layui-form-label">联系方式</label>
					    <div class="layui-input-block">
					      <input type="number" name="supplierContact" autocomplete="off" lay-verify="phone|required"  placeholder="" class="layui-input">
					    </div>
					</div>
					</div>
                   	<div class="layui-col-xs12 layui-col-sm6 layui-col-md6">
					<div class="layui-form-item">
					    <label class="layui-form-label">供应商电话</label>
					    <div class="layui-input-block">
					      <input type="number" name="supplierPhone" autocomplete="off" lay-verify="phone|required"  placeholder="" class="layui-input">
					    </div>
					</div>
					</div>
                   	<div class="layui-col-xs12 layui-col-sm6 layui-col-md6">
					<div class="layui-form-item">
					    <label class="layui-form-label">平均价格</label>
					    <div class="layui-input-block">
					      <input type="number" name="averagePrice" autocomplete="off"    placeholder="￥" class="layui-input">
					    </div>
					</div>
					</div>
                   	<div class="layui-col-xs12 layui-col-sm6 layui-col-md6">
                    <div class="layui-form-item">
                          <label class="layui-form-label">保质期</label>
                          <div class="layui-input-block">
                            <input type="text" name="expireTime" id="expireTime"  lay-verify="date"   autocomplete="off" class="layui-input" placeholder="yyyy-MM-dd HH:mm" >
                          </div>
                    </div>
                    </div>
                   	<div class="layui-col-xs12 layui-col-sm6 layui-col-md6">
                    <div class="layui-form-item">
                          <label class="layui-form-label">备注</label>
                          <div class="layui-input-block">
                            <input type="text" name="comment"   autocomplete="off" class="layui-input" placeholder="" >
                          </div>
                    </div>
                    </div>
                   	<div class="layui-col-xs12 layui-col-sm6 layui-col-md6">
                    <div class="layui-form-item">
                          <label class="layui-form-label">操作人员id</label>
                          <div class="layui-input-block">
                            <input type="number" name="createId"   autocomplete="off" class="layui-input" placeholder="" >
                          </div>
                    </div>
                    </div>
                   	<!--<div class="layui-col-xs12 layui-col-sm6 layui-col-md6">
                    <div class="layui-form-item">
                          <label class="layui-form-label">入库时间</label>
                          <div class="layui-input-block">
                            <input type="text" name="createTime" lay-verify="number" autocomplete="off" class="layui-input" placeholder="" >
                          </div>
                    </div>
                    </div>-->
                   	<div class="layui-col-xs12 layui-col-sm6 layui-col-md6">
                    <div class="layui-form-item">
                          <label class="layui-form-label">商户数量</label>
                          <div class="layui-input-block">
                            <input type="number" name="merchantNumber"   autocomplete="off" class="layui-input" placeholder="" >
                          </div>
                    </div>
                    </div>
                   	<div class="layui-col-xs12 layui-col-sm6 layui-col-md6">
                    <div class="layui-form-item">
                          <label class="layui-form-label">商品编码</label>
                          <div class="layui-input-block">
                            <input type="number" name="materialNumber"   autocomplete="off" class="layui-input" placeholder="" >
                          </div>
                    </div>
                    </div>
                   	<div class="layui-col-xs12 layui-col-sm6 layui-col-md6">
                    <div class="layui-form-item">
                          <label class="layui-form-label">产品条码</label>
                          <div class="layui-input-block">
                            <input type="text" name="barCode"   autocomplete="off" class="layui-input" placeholder="" >
                          </div>
                    </div>
                    </div>
                   	<div class="layui-col-xs12 layui-col-sm6 layui-col-md6">
                    <div class="layui-form-item">
                          <label class="layui-form-label">委托产品id</label>
                          <div class="layui-input-block">
                            <input type="number" name="commodityId"   autocomplete="off" class="layui-input" placeholder="" >
                          </div>
                    </div>
                    </div>
                   	<div class="layui-col-xs12 layui-col-sm6 layui-col-md6">
                    <div class="layui-form-item">
                          <label class="layui-form-label">产品编号</label>
                          <div class="layui-input-block">
                            <input type="number" name="commodityNumber"   autocomplete="off" class="layui-input" placeholder=""  >
                          </div>
                    </div>
					</div>
                </form>
            </div>
		</script><!--addBox结束-->
            <script src="js/jquery-3.2.1.min.js"></script>
			<script type="text/javascript" src="js/allajax.js"></script>
            <script>

            layui.use(['layer', 'form', 'element','table','laydate','laypage'], function(){
              var layer = layui.layer
              ,form = layui.form
              ,element = layui.element
              ,table = layui.table
              ,laydate = layui.laydate
              ,laypage = layui.laypage;
              
				var tableArray = new Array();
				EOListFn(1 ,100 );
				function EOListFn(curr ,limit ){
					AjaxPostFn('system/material/in/select?page='+curr+'&pagesize='+limit, "{}", function(jsonData) {
						$.each(jsonData.pageInfo.list, function(i, obj) {
							tableArray.push({
								"id": obj.id,
								"operation": " <a class='layui-btn layui-bg-red ' lay-event='DelThis'>删除</a>",
						        "entrustNumber": obj.entrustNumber,
						        "batchId": obj.batchId,
						        "locationId": obj.locationId,
						        "theNum": obj.theNum,
						        "supplierName": obj.supplierName,
						        "supplierContact": obj.supplierContact,
						        "supplierPhone": obj.supplierPhone,
						        "averagePrice": obj.averagePrice,
						     
						        "expireTime":getMyDate( obj.expireTime ) ,
						        "comment": obj.comment,
						        "createId": obj.createId,
//						        "createTime":"<input type='text' class='layui-input sTime'  value='"+ new Date(obj.createTime)+"'>"  ,
						        "merchantNumber": obj.merchantNumber,
						        "materialNumber": obj.materialNumber,
						        "barCode": obj.barCode,
						        "commodityId": obj.commodityId,
						        "commodityNumber": obj.commodityNumber
							});
						})
						
						//展示已知数据
						table.render({
							elem: '#EOtable',
							cols: [
								[ //标题栏
									
									{field: 'id', minWidth: '0%', width: '0%',type: 'space',style: 'display:none' },
									{field: 'operation',width: 100,title: '操作'},
									{field: 'entrustNumber',width: 100,title: '委托单号' , edit: 'text'},
									{field: 'batchId',width: 100,title: '批次id'},
									{field: 'locationId',width: 100,title: '提货点编码'},
									{field: 'theNum',width: 100,title: '入库数量',edit: 'text'},
									{field: 'supplierName',width: 200,title: '供应商名称' , edit: 'text'},
									{field: 'supplierContact',width: 200,title: '供应商联系方式' , edit: 'text'},
									{field: 'supplierPhone',width: 150,title: '供应商电话' , edit: 'text'},
									{field: 'averagePrice',width: 100,title: '平均价格' , edit: 'text'},
									{field: 'expireTime',width: 150,title: '保质期'},
									{field: 'comment',width: 100,title: '备注' , edit: 'text'},
									{field: 'createId',width: 100,title: '操作人员id'},
//									{field: 'createTime',width: 150,title: '入库时间'},
									{field: 'merchantNumber',width: 100,title: '商户数量' , edit: 'text'},
									{field: 'materialNumber',width: 100,title: '商品编码'},
									{field: 'barCode',width: 150,title: '产品条码'},
									{field: 'commodityId',width: 100,title: '委托产品id'},
									{field: 'commodityNumber',width: 100,title: '委托产品编号'},

								]
							],
							data: tableArray,
							size: 'lg',
							even: true,
							page: true, //是否显示分页
							done: function(){
//								 laypage.render({
//								    elem: 'layui-table-page1' //注意，这里的 test1 是 ID，不用加 # 号
//								    ,count: jsonData.pageInfo.total//数据总数，从服务端得到
//								    
//								    ,jump: function(obj, first){
//									    //obj包含了当前分页的所有参数，比如：
//									    console.log(obj.curr); //得到当前页，以便向服务端请求对应页的数据。
//									    console.log(obj.limit); //得到每页显示的条数
//									   
//									    //首次不执行
//									    if(!first){
//									      //do something
//									      EOListFn(obj.curr,obj.limit);
//									    }
//									  }
//								  });
							}
						});//数据渲染结束

					})
					
				}//EOListFn函数结束
				
				//日期选择
//				laydate.render({
//				   elem: lay('.sTime') //指定元素
//				 });
//				
				table.on('tool(table100)', function(obj){ 
                  var data = obj.data; //获得当前行数据
                  var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
                  var tr = obj.tr; //获得当前行 tr 的DOM对象
                 
                  if(layEvent === 'DelThis'){ //删除
                  	layer.confirm('是否删除该条分类信息', function(index) {
						AjaxPostFn('system/material/in/delete', "{'id':'" + data.id + "'}", function(jsonData) {
							if(jsonData.htmlState.status == 200) {
								layer.msg("删除成功");

							} else {}
						})
						obj.del();
						layer.close(index);

					});
                		
                  }
              	})
				
				
				//监听单元格编辑
				 table.on('edit(table100)', function(obj){
				    var value = obj.value //得到修改后的值
				    ,data = obj.data //得到所在行所有键值
				    console.log(data)
				    ,field = obj.field; //得到字段
				    AjaxPostFn('system/material/in/update',JSON.stringify(data) , function(jsonData) {
				    	console.log(jsonData)
						if(jsonData.htmlState.status == 200) {
							layer.msg("修改成功");
							
						}
					})
//				    layer.msg('[ID: '+ data.id +'] ' + field + ' 字段更改为：'+ value);
				 });
				 
				 $('.openwinbtn').on('click', function() {
                    var othis = $(this),
                        method = othis.data('method');
                    active[method] ? active[method].call(this, othis) : '';
                });
				 
				 var active = {
//                 弹出框事件
                    addmang:function(){
                        layer.open({
                        	type:1,
                            skin: 'layui-layer-molv',
                            title: '新增委托加工材料入库',
                            area: ['800px', '580px'],
                            content: $("#addBox").html(),
                            skin: 'demo-class',
                            btn: ["确认新增", "关闭"],
                            yes: function(index, layero) {
                                //按钮1的回调
                                 inputisNull("#addform input" ,function(){
                                 	var thisdata =JSON.stringify( $("#addform").serializeJson());
	                                 AjaxPostFn('system/material/in/insert',thisdata, function(jsonData) {
								    	
										if(jsonData.htmlState.status == 200) {
											layer.msg("增加成功");
											location.reload(); 
										}
									})
                                 })
                                
                                
                               
                            },
                            btn2: function(index, layero) {
                                //按钮2的回调
                            },
                            cancel: function() {
                                //右上关闭的回调
                            },success:function(){
                            	laydate.render({
								    elem: '#expireTime'
								    ,type:'datetime'
								    ,format:'yyyy-MM-dd HH:mm'
								});
                            }
                        })
                    }
                }

            });
           </script>
</body>
</html>